const {
  flattenArray
} = require('../../utils/util');
import {
  behavior as computedBehavior
} from 'miniprogram-computed'
import {
  storeBindingsBehavior
} from 'mobx-miniprogram-bindings'
import {
  store
} from '../../store/index'

Component({
  behaviors: [computedBehavior, storeBindingsBehavior],
  /**
   * 组件的属性列表
   */
  properties: {
    // 表头
    columns: {
      type: Array,
      value: []
    },
    // 表内容
    data: {
      type: Array,
      value: []
    },
    // 宽度
    width: {
      type: String,
      value: ''
    },
    // 高度
    height: {
      type: String,
      value: ''
    },
    // 是否要边框
    border: {
      type: Boolean,
      value: false
    }
  },
  // 全局变量
  storeBindings: {
    store,
    fields: {
      columnsCj: (store) => store.columnsCj
    },
    actions: {
      computeCj: 'computeCj'
    }
  },
  // // 监听属性
  watch: {
    'columns': function (columns) {
      this.computeCj(columns)
    },
  },
  // 计算属性
  computed: {
    getColumns(properties) {
      return flattenArray(properties.columns)
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
  }
})